package com.joycessh.action.cdgl;

import java.util.ArrayList;
import java.util.List;

import com.joycessh.PO.cdgl.VenuePO;
import com.joycessh.service.ICdglService;
import com.joycessh.service.impl.CdglServiceImpl;
import com.joycessh.util.DateJsonValueProcessor;
import com.opensymphony.xwork2.ActionSupport;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

@SuppressWarnings("serial")
public class ShowAllAction extends ActionSupport {
	private ICdglService cdglService;	
	private String result;	
	public String getResult() {
		return result;
	}
	public void setResult(String result) {
		this.result = result;
	}
	
	@Override
	public String execute() throws Exception {
		cdglService = new CdglServiceImpl();		
		try {
			//System.out.println("aaaaaaa");
			//HttpServletRequest request = ServletActionContext.getRequest();
			//String queryText = request.getParameter("query_text");						
			
			//System.out.println(queryText);
			//调用添加场地服务，返回提示信息
			List<VenuePO> show_all = new ArrayList<VenuePO>();
			show_all = cdglService.showAll();
			//System.out.print(query_result.iterator());
			
			//json Date类型数据处理，时间格式化( yyyy-MM-dd HH:mm:ss )
			//定义配置文件，并且注册时间类型 
			JsonConfig jsonConfig = new JsonConfig(); 
			jsonConfig.registerJsonValueProcessor(java.util.Date.class, new DateJsonValueProcessor("HH:mm")); 
			
			//Map<String,Object> map = new HashMap<String,Object>();

			//map.put("message", message);					 
			
			//将map对象转换成json类型数据*/
			JSONArray json = JSONArray.fromObject(show_all, jsonConfig);
			//System.out.println(json);
			//给result赋值，传递给页面
			result = json.toString();
			
		}catch(Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
}
